<%@ page import="com.situ.web.pojo.Student" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/4/3
  Time: 20:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/css/bootstrap.css"/>
</head>
<body>
   <%-- ${list}--%>
   <%
       //req.setAttribute("list", list);
       List<Student> list = (List<Student>) request.getAttribute("list");
   %>
   <a class="btn btn-primary" href="<%=request.getContextPath()%>/student_add.jsp">添加</a>
    <table class="table table-striped table-bordered">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>性别</td>
            <td>删除</td>
        </tr>
        <%
            for (Student student : list) {
        %>
                <tr>
                    <td><%=student.getId()%></td>
                    <td><%=student.getName()%></td>
                    <td><%=student.getAge()%></td>
                    <td><%=student.getGender()%></td>
                    <%--<td><a href="<%=request.getContextPath()%>/student?method=deleteById&id=<%=student.getId()%>">删除</a></td>--%>
                    <td><a href="javascript:deleteById(<%=student.getId()%>)">删除</a></td>
                </tr>
        <%
            }
        %>

    </table>

    <script>
        function deleteById(id) {
            var isDelete = confirm('您确认要删除么?');
            if (isDelete) {
                location.href = '<%=request.getContextPath()%>/student?method=deleteById&id=' + id
            }
        }
    </script>
</body>
</html>
